<?php
/**
 * index.php 首页控制器
 *
 *
 * @author          hyperblue
 * @version         0.1
 * @copyright       (C) 2011- *
 * @license	        http://www.bingceng.com
 * @lastmodify	    2011-11-16 00:18
 */
 
class index extends Controller {

    public function __construct() {
		parent::__construct();
		$this->admin_users_model = $this->load_model('admin_users');
    }
 
    public function do_index() {
        $this->tpl->display('index');
    }

    public function do_login() {
		if ($_POST['email'] && $_POST['password']) {
			if (!V_email($_POST['email'])) _redirect(_url('', array('error' => 'error_login_field_email')));
			if (!V_password($_POST['password'])) _redirect(_url('', array('error' => 'error_login_field_password')));
			$data = array(
				'email' => $_POST['email'],
				'password' => md5($_POST['password'])
			);
			if ($this->admin_users_model->op_login($data)) _redirect(_url(ROUTE_M));
			else _redirect(_url('', array('error' => 'error_login_incorrect')));
		}
		
		if ($_SESSION['bc_backend']['user_id']) _redirect(_url(ROUTE_M));
		
		$error_handler = $_GET['error'];
		$this->tpl->assign('error_handler', $error_handler);
		$this->tpl->display('login');
    }
	
	public function do_logout() {
		unset($_SESSION['bc_backend']);
		_redirect(_url(ROUTE_M.'/index/login'));
	}
}
?>
